package org.jeecg.modules.system.mapper;

import com.aliyun.oss.common.utils.StringUtils;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.UserPostDepartVo;

public class UserMapperProvider {
    public String listOfUser(UserPostDepartVo user){
        String sql = "select\n" +
                "sp.id  postId,\n" +
                "sp.name post,\n" +
                "su.id userId," +
                "su.username,\n" +
                "su.realname realname,\n" +
                "su.work_no,\n" +
                "su.phone,\n" +
                "GROUP_CONCAT(sd.id) selecteddeparts,\n" +
                "GROUP_CONCAT(sd.depart_name) departName,\n" +
                "su.password\n" +
                "from\n" +
                "sys_user su\n" +
                "left join sys_user_post sup on sup.USER_ID = su.id\n" +
                "left join sys_position sp on sp.id = sup.POST_ID\n" +
                "left join sys_user_depart sud on sud.user_id = su.id\n" +
                "left join sys_depart sd on sd.id = sud.dep_id\n" +
                "where su.del_flag = '0'";
        StringBuilder builder = new StringBuilder(sql);
        if (!StringUtils.isNullOrEmpty(user.getUsername())){
            builder.append("\nAND su.username like '%"+user.getUsername()+"%'");
        }
        if (!StringUtils.isNullOrEmpty(user.getRealname())){
            builder.append("\nAND su.realname like '%"+user.getRealname()+"%'");
        }
        if (!StringUtils.isNullOrEmpty(user.getWorkNo())){
            builder.append("\nAND su.work_no like '%"+user.getWorkNo()+"%'");
        }
        if (!StringUtils.isNullOrEmpty(user.getPost())){
            builder.append("\nAND sp.name like '%"+user.getPost()+"%'");
        }
        builder.append("\nGROUP BY\n" +
                "su.id");

        return builder.toString();
    }
}
